var WxParse = require('../../wxParse/wxParse.js');
//获取应用实例
var app = getApp() 
Page({
  data: {
  
  },
  onLoad: function (e) {
    var that = this;
    if(e&&e.id){
      var id = e.id;
      that.setData({
        id: id
      })
    }
    if (e && e.enterfrom) {
      var enterfrom = e.enterfrom == 'share' ? true : false;
      that.setData({
        enterfrom: enterfrom
      })
    }
    if (!app.globalData.plumSession) {
      console.log("暂未获取到session");
      app.wechatSq(that);
    } else {
      that.requestDetail();
    }
  },
  onPullDownRefresh:function(){
    var that = this;
    that.requestDetail();
  },
  requestDetail: function () {
    var that = this;
    wx.showLoading({
      title: '加载中',
      mask: true,
      time: 100000
    })
    wx.request({
      url: app.globalData.requestUrl,
      data: {
        map: 'applet_cake_store_detail_new',
        id: that.data.id
      },
      success: function (res) {
        console.log(res.data);
        if (res.data.ec == 200) {
          that.setData({
            detailInfo: res.data.data
          })
          console.log(that.data.detailInfo);
          wx.setNavigationBarTitle({
            title: res.data.data.name
          })
          var article = res.data.data.detail;
          // 富文本解析
          WxParse.wxParse('article', 'html', article, that, 5);
        } else {
          console.log(res.data)
          app.errorTip(that, res.data.em, 2000);
        }
      },
      complete: function () {
        wx.hideLoading();
        wx.stopPullDownRefresh();
      }
    });
  },
  seemap: function (e) {
    var latitude = e.currentTarget.dataset.latitude;
    var longitude = e.currentTarget.dataset.longitude;
    var address = e.currentTarget.dataset.address;
    var name = e.currentTarget.dataset.name;
    wx.openLocation({
      latitude: Number(latitude),
      longitude: Number(longitude),
      name: name,
      address: address,
      scale: 18
    })
  },
  contactTa: function (e) {
    var tel = e.currentTarget.dataset.tel;
    app.makeCallphone(tel);
  },
  onShareAppMessage: function () {
    var that = this;
    var id = that.data.id;
    var title = that.data.detailInfo.name;
    var shareInfo = app.globalData.shareInfo;
    title = shareInfo.shareTitle ? shareInfo.shareTitle : title;
    var cover = shareInfo.shareCover ? shareInfo.shareCover : '';
    app.getPoint(that);
    return {
      title: title,
      imageUrl: cover,
      path: '/subpages1/storeDetail/storeDetail?enterfrom=share&id=' + id
    }
  }
})
